package com.asialjim.wechat.cloud;

import com.asialjim.wechat.apiservice.AccessTokenService;
import com.asialjim.wechat.apiservice.enumeration.WeChatApiReturnEnumeration;
import com.asialjim.wechat.apiservice.exception.WeChatApiException;
import com.asialjim.wechat.pojo.account.WeChatAccountHolder;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <h1><em>ASIAL JIM JAVA DOC</em></h1><hr/>
 * <h2>CLASS DESCRIPTION <i>[ NAME: AccessTokenCloud ]</i></h2><strong>
 * <p>
 * </strong><p><p><em>Copyright &copy; Asial Jim Co., LTD</em><hr/>
 *
 * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
 * @version 1.0.0
 * @since 2021/3/30   &nbsp;&nbsp; JDK 8
 */
@RestController
@AllArgsConstructor
@RequestMapping("/we_chat/access_token")
public class AccessTokenCloud {
    private final AccessTokenService accessTokenService;

    @GetMapping
    public String get(String appid){
        if (StringUtils.isBlank(appid)){
            WeChatApiException.cast(WeChatApiReturnEnumeration.CODE_40086);
        }
        WeChatAccountHolder.setToUserName(appid);
        return accessTokenService.get();
    }
}
